<template>
  <div class="login">
   <el-card class="box-card">
  <div slot="header" class="clearfix">
    <span style="font-size:25px">登录</span>
  </div>
  <div>
   <el-form :label-position="labelPosition" label-width="80px" :model="formLabelAlign">
  <el-form-item label="账号：">
    <el-input v-model="formLabelAlign.name"></el-input>
  </el-form-item>
  <el-form-item label="密码：">
    <el-input v-model="formLabelAlign.password" show-password></el-input>
  </el-form-item>
  <el-form-item label="验证码:" style="margin-top: 15px;">
    <el-input v-model="formLabelAlign.yzm" style="width:180px !important; height: 47px !important;" @blur="ewmis" v-on:keyup.enter="ewmis"></el-input>
    <span v-html="data.captcha" style="float: right;" @click="shuaxing"></span>
  </el-form-item>
  <el-form-item>
    <el-button type="primary" round style="width:80% !important; height: 47px !important;margin: auto;" @click="login">登录</el-button>
  </el-form-item>
</el-form>
  </div>
</el-card>

  </div>
</template>

<script>
import { geterweima, iserweima, istrue } from '@/api/login'
export default {
  data() {
    return {
      labelPosition: 'right',
      formLabelAlign: {
        name: '',
        password: '',
        yzm: '',
      },
      data: '',
      ewmistrue: '',
      admin: '',
    }
  },
  methods: {
    async login() {
      console.log(this.formLabelAlign)
      this.admin = await istrue(this.formLabelAlign)
      console.log(this.admin.data)
      if (this.admin.status !== 200) {
        this.$message.error(this.admin.message)
      } else {
        this.$store.dispatch('admin/getdata', { data: this.admin.data.userInfo, token: this.admin.data.token })
        this.$router.push({ path: '/dashboard' })
      }
    },
    async shuaxing() {
      this.data = await geterweima()
    },
    async ewmis(e) {
      this.ewmistrue = await iserweima(e.target.value)
      console.log(this.ewmistrue)
      if (this.ewmistrue.state !== 200) {
        this.$message.error('验证码错勒')
        e.target.value = ''
      }
    },
  },
  async created() {
    this.data = await geterweima()
  },
}
</script>

<style lang="scss" scoped>
   .text {
    font-size: 14px;
  }

  .item {
    margin-bottom: 18px;
  }

  .clearfix:before,
  .clearfix:after {
    display: table;
    content: "";
  }
  .clearfix:after {
    clear: both
  }

  .box-card {
    width: 480px;
    height: 380px;
    position: absolute;
    top:0;
    left: 0;
    right: 0;
    bottom: 0;
    margin: auto;
  }
</style>
